"use strict";

var _stringify = require("babel-runtime/core-js/json/stringify");

var _stringify2 = _interopRequireDefault(_stringify);

var _promise = require("babel-runtime/core-js/promise");

var _promise2 = _interopRequireDefault(_promise);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/*
	发表话题
	@param {cnt}  将要插入的内容
	@param {function} callback

*/
var async = require("async");
var db = require("./config.js").db;

exports.doc_publish_sub = function (cnt, callback) {
    console.log("save**************");
    console.log(cnt);
    let query = `INSERT INTO article(
    author,
    author_id,
    title,
    content,
    img_list,
    is_ess,
    shequ_id
)
VALUES
    (
        ?,?,?,?,?,?,?
    );
`;
    return new _promise2.default(function (resolver, reject) {
        db.query(query, [cnt.author, cnt.author_id, cnt.title, cnt.content, cnt.img_list, cnt.is_ess, cnt.shequ_id], function (err, list) {

            if (err) {
                reject(err);
            };
            db.query(`select last_insert_id() as doc_id`, function (err, data) {
                if (err) {
                    reject(err);
                }
                resolver({ doc_id: JSON.parse((0, _stringify2.default)(data))[0].doc_id });
            });
        });
    });
};

// db.query('INSERT INTO `article_list`(`id`, `title`, `url`, `class_id`, `created_time`) VALUES (?, ?, ?, ?, ?)',
//           [item.id, item.title, item.url, class_id, created_time], next);